/*
 * @Author: yixin 
 * @Date: 2019-11-30 23:03:00 
 * @Last Modified by: yixin
 * @Last Modified time: 2019-12-03 23:46:41
 * 获取datePicker日期数据
 */
var datePicker = {};

datePicker.getMonthDate = (year, month) => {

  var ret = [];

  if(!year||!month){
    var today = new Date();
    year = today.getFullYear;
    month = today.getMonth + 1;
  }

  var firstDay = new Date(year, month-1, 1);
  var firstWeekDay = firstDay.getDay() == 0 ? 7 : firstDay.getDay();
  var lastDayOfLastMonth = new Date(year, month-1, 0);
  var lastDateOfLastMonth = lastDayOfLastMonth.getDate();

  var preMonthDayCount = firstWeekDay - 1;

  var lastDay = new Date(year, month, 0);
  var lastDate = lastDay.getDate();

  for(var i = 0; i < 7 * 6; i++){
    var date = i + 1 - preMonthDayCount;
    var showDate = date;
    var thisMonth = month;
    var disabled = false;
    // 上一月
    if(date<=0){
      thisMonth = month - 1;
      // showDate = lastDateOfLastMonth + date;
      showDate = ''
    }else if(date > lastDate){
      thisMonth = month + 1;
      // showDate = showDate - lastDate;
      showDate = ''
    }else if(thisMonth == (new Date().getMonth()+1) && date > (new Date()).getDate()){
      disabled = true
    }
    if(thisMonth === 0) thisMonth = 12;
    if(thisMonth === 13) thisMonth = 1;

    ret.push({
      month: thisMonth,
      date: date,
      showDate: showDate,
      disabled
    })
  }

  return {
    year: firstDay.getFullYear(),
    month: firstDay.getMonth()+1,
    days: ret
  }
}

export default datePicker;